Skip to content

Conversation

@boneskull
Copy link
Owner

Summary

Consolidates the type-specific to satisfy and to deep equal assertions into single generic versions that work on any value type.

Changes

Assertion Consolidation

Before: 6 type-specific assertions

  • {object} to satisfy {any}
  • {array} to satisfy {any}
  • {object} to deep equal {object}
  • {array} to deep equal {array}
  • {Map} to deep equal {Map}
  • {Set} to deep equal {Set}

After: 2 generic assertions

  • {unknown} to satisfy {unknown}
  • {unknown} to deep equal {unknown}

New Feature: Cross-Type Satisfaction

The consolidated to satisfy assertion now supports validating properties on any value that has them:

// Arrays satisfying object shapes
expect([1, 2, 3], 'to satisfy', { length: 3 });

// Functions satisfying object shapes
expect(function myFn() {}, 'to satisfy', { name: 'myFn' });

// Constructors satisfying object shapes
expect(Promise, 'to satisfy', {
  reject: expect.it('to be a function'),
  resolve: expect.it('to be a function'),
});

New valueToSchema Options

  • literalEmptyArrays: When false (default), empty arrays [] match any array (like literalEmptyObjects for objects)
  • permissivePropertyCheck: When true, validates object shapes against any value with properties (functions, arrays, etc.) using the in operator

Documentation

  • Moved to satisfy documentation from object.md to equality.md
  • Expanded to deep equal examples to show primitives, Map, Set
  • Added cross-type satisfaction examples
  • Added redirects from type-specific sections to unified documentation

Testing

  • 17 new property tests for permissivePropertyCheck covering functions, arrays, classes, getters, and edge cases
  • All existing tests pass (1273 tests)
  • Handles edge cases like restricted properties (arguments, caller, callee on strict mode functions)

Replaces 6 type-specific assertions with 2 generic versions:
- objectSatisfiesAssertion + arraySatisfiesAssertion → satisfiesAssertion
- object/array/map/setDeepEqualAssertion → deepEqualAssertion

Both now accept unknown subjects and parameters, delegating
type validation to valueToSchema. This simplifies the API
while maintaining equivalent behavior for same-type comparisons.

Includes updated property tests, snapshot tests, and new unit
tests covering primitive equality cases.
…ction

Adds a new 'permissivePropertyCheck' option to valueToSchema that
allows checking object properties on any value type (functions,
arrays, etc.), not just plain objects. Properties are checked
using the 'in' operator which works with non-enumerable and
inherited properties.

This enables use cases like:
- expect([1,2,3], 'to satisfy', {length: 3})
- expect(Promise, 'to satisfy', {reject: expect.it('to be a function')})

The option is automatically enabled for 'to satisfy' assertions
via valueToSchemaOptionsForSatisfies.

Includes comprehensive tests for cross-type satisfaction scenarios.
…ases

- Add literalEmptyArrays option: when false (default), empty arrays []
  match any array (like literalEmptyObjects for objects)
- Fix permissive property check for array elements: disable permissive
  mode inside arrays to avoid union conflicts with z.any()
- Handle inaccessible properties (arguments/caller/callee on strict
  mode functions) gracefully with try/catch
- Add comprehensive property tests for permissivePropertyCheck option
  covering functions, arrays, classes, getters, and edge cases
- Move 'to satisfy' from object.md to equality.md
- Expand 'to deep equal' examples to show primitives, Map, Set
- Add cross-type satisfaction examples (arrays with length, Promise)
- Replace redundant Map/Set deep equal sections with redirects
- Add redirects in object.md and collection.md pointing to equality.md
Copilot AI review requested due to automatic review settings January 15, 2026 23:36
@boneskull boneskull added enhancement New feature or request assertions CRUD operations on built-in assertions labels Jan 15, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR consolidates six type-specific assertions ({object}, {array}, {Map}, {Set} variants of to satisfy and to deep equal) into two generic assertions that work with any value type. The consolidation enables a new "cross-type satisfaction" feature where properties can be validated on any value that has them (arrays, functions, constructors, etc.).

Changes:

  • Consolidated 6 type-specific assertions into 2 generic ones: {unknown} to satisfy {unknown} and {unknown} to deep equal {unknown}
  • Added permissivePropertyCheck option to enable property validation on non-object types using the in operator
  • Added literalEmptyArrays option to control whether empty arrays match any array (similar to existing literalEmptyObjects)

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
site/assertions/object.md Replaced detailed to satisfy documentation with redirect to equality.md
site/assertions/equality.md Added comprehensive documentation for consolidated to satisfy and expanded to deep equal with primitives, Maps, Sets examples
site/assertions/collection.md Added redirects for array/Map/Set specific assertions to consolidated versions
packages/bupkis/test/property/value-to-schema.test.ts Added 17 property tests for permissivePropertyCheck covering functions, arrays, classes, getters, edge cases
packages/bupkis/test/assertion/satisfy-deep-equal.test.ts New test file with 396 lines covering primitives, objects, arrays, cross-type satisfaction, negation, edge cases
packages/bupkis/test/property/configs/sync-parametric.ts Updated test configurations to use consolidated assertions with expanded test cases for primitives
packages/bupkis/test/assertion/assertion-classification.test.ts Updated assertion count from 86 to 82 (net reduction of 4 after consolidation)
packages/bupkis/test/assertion-error/*.snapshot Updated snapshots to reflect new assertion IDs
packages/bupkis/test/assertion-error/sync-parametric-error.test.ts Updated to use consolidated assertions
packages/bupkis/test-data/sync-parametric-generators.ts Consolidated generators to support primitives, objects, arrays, Maps, Sets
packages/bupkis/src/value-to-schema.ts Added literalEmptyArrays and permissivePropertyCheck options with comprehensive implementation
packages/bupkis/src/assertion/impl/sync.ts Updated exports to remove type-specific assertions
packages/bupkis/src/assertion/impl/sync-parametric.ts Replaced 6 type-specific assertions with 2 generic ones

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Update @bupkisAssertionCategory from 'comparison' to 'equality' and
fix @bupkisAnchor to match documentation anchors.
…emantics

Empty arrays [] now mean 'any array' in satisfaction mode, so invalid
tests must use non-empty expected args to actually test argument
mismatches in event emission assertions.
Copilot AI review requested due to automatic review settings January 15, 2026 23:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@boneskull boneskull merged commit edf0aa0 into main Jan 15, 2026
20 checks passed
@boneskull boneskull deleted the satisfy-consolidation branch January 15, 2026 23:59
@github-actions github-actions bot mentioned this pull request Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

assertions CRUD operations on built-in assertions enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants